package kxfang.com.common.core.viewModel;

import android.app.Activity;
import android.content.Context;

import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;

public abstract class BaseViewModel<T,V extends ViewDataBinding> {

    protected T instance;
    protected V binding;
    protected Context context;

    public BaseViewModel(T instance, V binding){
        this.instance = instance;
        this.binding = binding;
        if(instance instanceof Activity){
            context = ((Activity) instance).getBaseContext();
        }else if(instance instanceof Fragment){
            context = ((Fragment) instance).getContext();
        }
    }

    /**
     * 在子类构造器自行调用
     */
    public abstract void initData();
}
